<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Constructs EvPeriodic watcher object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="evperiodic.at.html">EvPeriodic::at</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="evperiodic.createstopped.html">EvPeriodic::createStopped</a></div>
 <div class="up"><a href="class.evperiodic.html">EvPeriodic</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="evperiodic.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">EvPeriodic::__construct</h1>
  <p class="verinfo">(PECL ev &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">EvPeriodic::__construct</span> &mdash; <span class="dc-title">Constructs EvPeriodic watcher object</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-evperiodic.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><strong>EvPeriodic::__construct</strong></span>
    ( <span class="methodparam">
    <span class="type">double</span>
     <code class="parameter">$offset</code>
   </span>
   , <span class="methodparam">
    <span class="type">string</span>
     <code class="parameter">$interval</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$reschedule_cb</code>
   </span>
   , <span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$callback</code>
   </span>
   [, <span class="methodparam">
    <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$data</code>
    <span class="initializer"> = <strong><code>NULL</code></strong></span>
   </span>
   [, <span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$priority</code>
    <span class="initializer"> = 0</span>
   </span>
  ]] )</div>

  <p class="para rdfs-comment">
   Constructs EvPeriodic watcher object and starts it automatically.
   <span class="methodname"><a href="evperiodic.createstopped.html" class="methodname">EvPeriodic::createStopped()</a></span>
   method creates stopped periodic watcher.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-evperiodic.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>

     <em><code class="parameter">offset</code></em>
    </dt>

    <dd>

     <p class="para">
      See
      <a href="ev.periodic-modes.html" class="link">Periodic watcher operation modes</a>
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">interval</code></em>
    </dt>

    <dd>

     <p class="para">
      See
      <a href="ev.periodic-modes.html" class="link">Periodic watcher operation modes</a>
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">reschedule_cb</code></em>
    </dt>

    <dd>

     <p class="para">
      Reschedule callback. You can pass <strong><code>NULL</code></strong>. See
      <a href="ev.periodic-modes.html" class="link">Periodic watcher operation
     modes</a>
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">callback</code></em>
    </dt>

    <dd>

     <p class="para">
      See
      <a href="ev.watcher-callbacks.html" class="link">Watcher callbacks</a>
      .
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">data</code></em>
    </dt>

    <dd>

     <p class="para">
      Custom data associated with the watcher.
     </p>
    </dd>

   
   
    <dt>

     <em><code class="parameter">priority</code></em>
    </dt>

    <dd>

     <p class="para">
      <a href="class.ev.html#ev.constants.watcher-pri" class="link">Watcher priority</a>
     </p>
    </dd>

   
  </dl>

 </div>

 <div class="refsect1 returnvalues" id="refsect1-evperiodic.construct-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns EvPeriodic object on success.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-evperiodic.construct-examples">
  <h3 class="title">范例</h3>

 <div class="example" id="example-3534">
   <p><strong>Example #1 Periodic timer. Use reschedule callback</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Tick&nbsp;each&nbsp;10.5&nbsp;seconds<br /><br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">reschedule_cb&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$watcher</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$now</span><span style="color: #007700">)&nbsp;{<br />&nbsp;return&nbsp;</span><span style="color: #0000BB">$now&nbsp;</span><span style="color: #007700">+&nbsp;(</span><span style="color: #0000BB">10.5</span><span style="color: #007700">.&nbsp;-&nbsp;</span><span style="color: #0000BB">fmod</span><span style="color: #007700">(</span><span style="color: #0000BB">$now</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10.5</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$w&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">EvPeriodic</span><span style="color: #007700">(</span><span style="color: #0000BB">0.</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0.</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"reschedule_cb"</span><span style="color: #007700">,&nbsp;function&nbsp;(</span><span style="color: #0000BB">$w</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$revents</span><span style="color: #007700">)&nbsp;{<br />&nbsp;echo&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />});<br /></span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">run</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-3535">
   <p><strong>Example #2 Periodic timer. Tick every 10.5 seconds starting at now</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Tick&nbsp;every&nbsp;10.5&nbsp;seconds&nbsp;starting&nbsp;at&nbsp;now<br /></span><span style="color: #0000BB">$w&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">EvPeriodic</span><span style="color: #007700">(</span><span style="color: #0000BB">fmod</span><span style="color: #007700">(</span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">now</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">10.5</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">10.5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;function&nbsp;(</span><span style="color: #0000BB">$w</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$revents</span><span style="color: #007700">)&nbsp;{<br />&nbsp;echo&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />});<br /></span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">run</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-3536">
   <p><strong>Example #3 Hourly watcher</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$hourly&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">EvPeriodic</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3600</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;function&nbsp;()&nbsp;{<br />&nbsp;echo&nbsp;</span><span style="color: #DD0000">"once&nbsp;per&nbsp;hour\n"</span><span style="color: #007700">;<br />};<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-evperiodic.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member">
    <a href="ev.periodic-modes.html" class="link">Periodic watcher operation modes</a>
   </li>
   <li class="member">
    <a href="class.evtimer.html" class="classname">EvTimer</a>
   </li>
   <li class="member">
    <span class="methodname"><a href="evperiodic.createstopped.html" class="methodname" rel="rdfs-seeAlso">EvPeriodic::createStopped()</a> - Create a stopped EvPeriodic watcher</span>
   </li>
  </ul>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="evperiodic.at.html">EvPeriodic::at</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="evperiodic.createstopped.html">EvPeriodic::createStopped</a></div>
 <div class="up"><a href="class.evperiodic.html">EvPeriodic</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
